#include "../lib/Coordonnes.hpp"
#include <iostream>
#include <cassert>
#include <fstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

unsigned int Transforme_Coord_2d_1d ( const Coord * P, unsigned int taille)
{
    return P->y*taille+P->x;
}

void Init_Coord ( Coord * C)
{
    C->x = 0;
    C->y = 0;
}

Coord * Creer_Coord()
{
    Coord * Temp = new Coord;
    Init_Coord ( Temp );

    return Temp;
}

void Testament_Coord ( Coord * C)
{
   delete C;
}

void Affecte_Coord ( Coord * C, unsigned int x, unsigned int y)
{
    C->x = x;
    C->y = y;
}

void Copie_Coord ( Coord * C, const Coord * A)
{
    C->x = A->x;
    C->y = A->y;
}


void Affiche_Coord ( const Coord * C)
{
    cout << " ( "<< C->x << ","<< C->y<< " ) ";
}

unsigned int Retourne_X  ( const Coord * C)
{
    return C->x;
}

unsigned int Retourne_Y  ( const Coord * C)
{
    return C->y;
}

void Modifie_X (Coord * C, int x)
{
    if((x+C->x) >= 0)
    {
        C->x = C->x + x;
    }

}



void Modifie_Y (Coord * C, int y)
{
    if((y+C->y) >= 0)
    {
        C->y = C->y + y;
    }

}

int TestRegressionCoord ()
{
    int i = 1;

    Coord * C = Creer_Coord();
    Coord * A = Creer_Coord();

    assert (C->x == 0);
    assert (C->y == 0);
    assert (A->x == 0);
    assert (A->y == 0);

    cout<<"Test du module Coordonnees : Entrez les valeurs à tester"<<endl;
    unsigned int x;
    cout<<"x : "<<endl;
    cin>>x;

    unsigned int y;
    cout<<"y : "<<endl;
    cin>>y;

    int xx;
    cout<<"X : "<<endl;
    cin>>xx;
    int yy;
    cout<<"Y : "<<endl;
    cin>>yy;

    Affecte_Coord (C,x,y);
    assert(C->x >= 0);
    assert(C->y >= 0);

    x = Retourne_X  (C);
    assert(x >= 0);
    assert(C->x == x);

    y = Retourne_Y  (C);
    assert(y >= 0);
    assert(C->y == y);

    Copie_Coord (C, A);
    assert(C->x == A->x);
    assert(C->y == A->y);

    Modifie_X (C,xx);
    assert(C->x >= 0);

    Modifie_Y (C,yy);
    assert(C->y >= 0);

    Testament_Coord (C);
    Testament_Coord (C);

    return i;

}
